package thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

// 自定义Callable任务类
class MyCallable implements Callable<String> {
    private String taskName;
    private int loopCount;

    public MyCallable(String taskName, int loopCount) {
        this.taskName = taskName;
        this.loopCount = loopCount;
        System.out.println("创建Callable任务: " + taskName);
    }

    @Override
    public String call() throws Exception {
        System.out.println("执行Callable任务: " + taskName);
        int sum = 0;

        for(int i = 1; i <= loopCount; i++) {
            System.out.println(taskName + " 处理中: " + i);
            sum += i;
            Thread.sleep(300); // 模拟耗时操作
        }

        return taskName + " 计算结果: " + sum;
    }
}